package com.haixiaoke.saas.enterprise.apartment.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.apartment.domain.ServiceFacilities;
import com.haixiaoke.saas.apartment.service.IServiceFacilitiesService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋设施Controller
 *
 * @author xiaolong
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/enterprise/apartment/facilities")
public class EnterpriseServiceFacilitiesController extends BaseController {
    @Autowired
    private IServiceFacilitiesService houseFacilitiesService;

    /**
     * 查询房屋设施列表
     */
    @GetMapping("/list")
    public AjaxResult list(ServiceFacilities serviceFacilities) {
        List<ServiceFacilities> list = houseFacilitiesService.selectHouseFacilitiesList(serviceFacilities);
        return AjaxResult.success(list);
    }

    /**
     * 导出房屋设施列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceFacilities serviceFacilities) {
        List<ServiceFacilities> list = houseFacilitiesService.selectHouseFacilitiesList(serviceFacilities);
        ExcelUtil<ServiceFacilities> util = new ExcelUtil<ServiceFacilities>(ServiceFacilities.class);
        util.exportExcel(response, list, "房屋设施数据");
    }

    /**
     * 获取房屋设施详细信息
     */
    @GetMapping(value = "/{facilitiesId}")
    public AjaxResult getInfo(@PathVariable("facilitiesId") Long facilitiesId) {
        return success(houseFacilitiesService.selectHouseFacilitiesByFacilitiesId(facilitiesId));
    }

    /**
     * 新增房屋设施
     */
    @PostMapping
    public AjaxResult add(@RequestBody ServiceFacilities serviceFacilities) {
        return toAjax(houseFacilitiesService.insertHouseFacilities(serviceFacilities));
    }

    /**
     * 修改房屋设施
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceFacilities serviceFacilities) {
        return toAjax(houseFacilitiesService.updateHouseFacilities(serviceFacilities));
    }

    /**
     * 删除房屋设施
     */
    @DeleteMapping("/{facilitiesIds}")
    public AjaxResult remove(@PathVariable Long[] facilitiesIds) {
        return toAjax(houseFacilitiesService.deleteHouseFacilitiesByFacilitiesIds(facilitiesIds));
    }
}
